﻿using System;
using System.Drawing;

namespace DirectDrawWrapper
{
    internal static class ColorUtil
    {



        public static uint GetColor(ref Color color, ref DDPIXELFORMAT dDPIXELFORMAT)
        {
            // Just 565 for now.
            byte red = (byte)((color.R * 0x1F) / 0xFF);
            byte green = (byte)((color.G * 0x3F) / 0xFF);
            byte blue = (byte)((color.B * 0x1F) / 0xFF);

            //byte red = (byte)((color.R / 0xFF) * 0x1F);
            //byte green = (byte)((color.G / 0xFF) * 0x3F);
            //byte blue = (byte)((color.B / 0xFF) * 0x1F);


            return (uint)(
                (red & 0x1F) << 0xb |
                (green & 0x3F) << 0x5 |
                (blue & 0x1F)
            );
            
        }


        private static int GetMask(byte value, byte maxSize, int start, int end)
        {
            throw new NotImplementedException();
        }
        private static unsafe void GetMaskSize(int mask, out int start, out int end)
        {
            int tempMask, count = sizeof(int);
            bool started = false;

            start = end = 0;

            for (int i = 0; i < count; i++)
            {
                tempMask = 1 << i;

                if ((mask & tempMask) == tempMask)
                {
                    if (!started)
                    {
                       end = start = i;
                    }
                    else
                    {
                        end = i;
                    }
                }
            }
        }

    }
}
